/**
 * Created by 丸子 on 2018/7/20 0020.
 */
// import store from '../store'
// import * as sessionTypes from '../store/session/types'
import Vue from 'vue'
import {stringify} from 'qs'

// 路径参数
export function $url (path, query) {
  const queryString = Object.keys(query || {}).map((key) => {
    return key + '=' + query[key]
  }).join('&')
  return '/' + path + '.html' + (queryString ? ('?' + queryString) : '')
}

// 路径带参数
export function $gotoUrl (path, query) {
  location.assign($url(path, query))
}

// 路径不带参数
export function $webUrl (path) {
  return window.WEB_URL + path
}

// 本地开发图片路径
export function $serverImg (path) {
  if (path == null) {
    return ''
  }
  if (process.env.NODE_ENV === 'production') {
    return window.API_HOST + path
  }
  return window.API_HOST + path
}

// catch
export function $alertAxiosError (name, error) {
  const message = `请求${name || ''}数据失败: ${error.message || error.data || error.data.message || ''}`
  setTimeout(()=>{
    Vue.prototype.$toast.fail(message)
  })
}

// 时间转换0000-00-00
export function $getTime (dateStr) {
  const date = new Date(dateStr)
  const Month = date.getMonth() + 1
  const Day = date.getDate()
  const Y = date.getFullYear() + '-'
  const M = Month < 10 ? '0' + Month + '-' : Month + '-'
  const D = Day + 1 < 10 ? '0' + Day : Day
  return Y + M + D
}

// post请求参数
export function $qsStringify (params) {
  return stringify(params || {})
}


